<?php
/**
 * Created by PhpStorm.
 * User: eddy
 * Date: 2018/3/16
 * Time: 23:37
 */

namespace iBrand\Shop\Backend\Http\Controllers;


use iBrand\Shop\Core\Models\Refund;
use iBrand\Shop\Core\Repositories\RefundRepository;
use Encore\Admin\Facades\Admin as LaravelAdmin;
use Encore\Admin\Layout\Content;

class RefundController extends Controller
{
    protected $refundRepository;

    public function __construct(RefundRepository $refundRepository)
    {
        $this->refundRepository = $refundRepository;
    }

    public function index()
    {
        $shop_id = session('shop_id');
        $view = request('status');
//        $where['channel'] = 'shop';
        $where['shop_id'] = $shop_id;

        $value = '';
        if (!empty(request('value'))) {
            if (request('field') == 'order_no') {
                $value = request('value');
            } else {
                $where['refund_no'] = ['like', '%' . request('value') . '%'];
            }
        }

        $refunds = $this->refundRepository->getRefundsPaginated($view, $where, $value);

        //return view('shop-backend::refund.index', compact('refunds'));


        return LaravelAdmin::content(function (Content $content) use($refunds){

            $content->header('售后列表');

            if(session()->has('shop_name')){

                $content->description(session('shop_name'));
            }

            $content->breadcrumb(
                ['text' => '门店管理', 'url' => 'shop/list/store', 'no-pjax' => 1],
                ['text' => '售后列表', 'url' => '', 'no-pjax' => 1,'left-menu-active'=>'售后列表']
            );


            $content->body(view('shop-backend::refund.index', compact('refunds')));
        });

    }

    public function show($id)
    {
        $refund = $this->refundRepository->find($id);

        return LaravelAdmin::content(function (Content $content) use($refund){

            $content->header('售后详情');

            if(session()->has('shop_name')){

                $content->description(session('shop_name'));
            }

            $content->breadcrumb(
                ['text' => '售后列表', 'url' => 'shop/info/refund?shop_id=', 'no-pjax' => 1],
                ['text' => '售后详情', 'url' => '', 'no-pjax' => 1,'left-menu-active'=>'售后列表']
            );

            $content->body(view('shop-backend::refund.show', compact('refund')));
        });
    }

}